package com.frank.http.expand;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

import com.frank.http.base.AsyncHttpClient;
import com.frank.http.base.AsyncHttpResponseHandler;
import com.frank.http.base.RequestParams;
import com.frank.http.encryp.EncrypException;
import com.frank.http.encryp.HttpMethod;

/**
 * 网络请求数据封装类
 * 
 * @author Frank
 * @version 1.0 Create by 2016.02.24
 */
public class CopyOfCacheAsyncHttpClient extends CacheAsyncHttpBase {
	private final String TAG = CopyOfCacheAsyncHttpClient.class.getSimpleName();
	private AsyncHttpClient client = null;
	private Context context;
	private ACache aCache;
	private int cacheTime = 604800;
	private boolean isInterceptError = false;
	private Tools toastTools;
	private NetLoadProcess netLoadProcess;

	public CopyOfCacheAsyncHttpClient(AsyncHttpClient client, Context context) {
		super();
		this.client = client;
		this.context = context;
	}

	/**
	 * 设置缓存
	 */
	public void setAcache(ACache aCache) {
		this.aCache = aCache;
	}

	/**
	 * 设置缓存时间
	 */
	public void setToastTools(Tools toastTools) {
		this.toastTools = toastTools;
	}

	/**
	 * 设置缓存时间
	 */
	public void setAcacheTime(int cacheTime) {
		this.cacheTime = cacheTime;
	}

	/**
	 * 是否拦截错误
	 */
	public void isInterceptError(boolean isInterceptError) {
		this.isInterceptError = isInterceptError;
	}

	/**
	 * 发送直接传请求体的 post请求
	 * 
	 * @param url
	 * @param params
	 * @param cacheAsyncHttpResponseHandler
	 */
	public void post(final String url, HttpEntity entity,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			return;

		AsyncHttpResponseHandler asyncHttpResponseHandler = new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody) {
				String string = new String(responseBody);
				Log.i(TAG, "string：" + string);

			}

			@Override
			public void onFailure(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody,
					Throwable error) {
			}

		};

		client.post(context, url, entity, null, asyncHttpResponseHandler,
				encryption);
	}

	@Override
	public void head(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.head(
				url,
				getAsyncHttpResponseHandler(HttpMethod.HEAD, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void head(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.head(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.HEAD, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void head(Context context, String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.head(
				context,
				url,
				getAsyncHttpResponseHandler(HttpMethod.HEAD, url,
						cacheAsyncHttpResponseHandler));

	}

	@Override
	public void head(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.head(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.HEAD, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void head(Context context, String url, Header[] headers,
			RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.head(
				context,
				url,
				headers,
				params,
				getAsyncHttpResponseHandler(HttpMethod.HEAD, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				url,
				getAsyncHttpResponseHandler(HttpMethod.GET, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.GET, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(Context context, String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				url,
				getAsyncHttpResponseHandler(HttpMethod.GET, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.GET, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(Context context, String url, Header[] headers,
			RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				context,
				url,
				headers,
				params,
				getAsyncHttpResponseHandler(HttpMethod.GET, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void get(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.GET, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				url,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				url,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						cacheAsyncHttpResponseHandler), encryption);
	}

	/**
	 * 发送post请求
	 * 
	 * @param url
	 * @param params
	 * @param cacheAsyncHttpResponseHandler
	 */
	@Override
	public void post(String url, RequestParams requestParams,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				url,
				requestParams,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						requestParams, cacheAsyncHttpResponseHandler),
				encryption);
	}

	@Override
	public void post(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.POST, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.POST, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.POST, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						cacheAsyncHttpResponseHandler), encryption);
	}

	@Override
	public void post(Context context, String url, Header[] headers,
			RequestParams params, String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				headers,
				params,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.POST, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void post(Context context, String url, Header[] headers,
			HttpEntity entity, String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.post(
				context,
				url,
				headers,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.POST, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				url,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(Context context, String url, Header[] headers,
			HttpEntity entity, String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				context,
				url,
				headers,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void patch(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.patch(
				url,
				getAsyncHttpResponseHandler(HttpMethod.PATCH, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void patch(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.patch(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PATCH, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void patch(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.patch(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PATCH, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void patch(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.patch(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.PATCH, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void patch(Context context, String url, Header[] headers,
			HttpEntity entity, String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.patch(
				context,
				url,
				headers,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.PATCH, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				url,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(Context context, String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				context,
				url,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(Context context, String url, Header[] headers,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				context,
				url,
				headers,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(Context context, String url, Header[] headers,
			RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				context,
				url,
				headers,
				params,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url, params,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void delete(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler));
	}

	@Override
	public void put(Context context, String url, HttpEntity entity,
			String contentType,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				context,
				url,
				entity,
				contentType,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url,
						cacheAsyncHttpResponseHandler), encryption);
	}

	@Override
	public void put(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				context,
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url, params,
						cacheAsyncHttpResponseHandler), encryption);
	}

	@Override
	public void put(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url, params,
						cacheAsyncHttpResponseHandler), encryption);
	}

	@Override
	public void put(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.put(
				url,
				getAsyncHttpResponseHandler(HttpMethod.PUT, url,
						cacheAsyncHttpResponseHandler), encryption);
	}

	@Override
	public void get(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				url,
				getAsyncHttpResponseHandler(HttpMethod.GET, url,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void get(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.GET, url, params,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void get(Context context, String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				context,
				url,
				getAsyncHttpResponseHandler(HttpMethod.GET, url,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void get(Context context, String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.get(
				context,
				url,
				getAsyncHttpResponseHandler(HttpMethod.GET, url, params,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void delete(String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				url,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void delete(Context context, String url,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				context,
				url,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url,
						cacheAsyncHttpResponseHandler), encryption);

	}

	@Override
	public void delete(String url, RequestParams params,
			CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler,
			boolean encryption) {
		if (client == null)
			try {
				throw new EncrypException("client不能为空");
			} catch (EncrypException e) {
				e.printStackTrace();
			}
		client.delete(
				url,
				params,
				getAsyncHttpResponseHandler(HttpMethod.DELETE, url, params,
						cacheAsyncHttpResponseHandler), encryption);

	}

	/**
	 * 获得请求响应信息
	 * 
	 * @param url
	 * @param requestParams
	 * @param cacheAsyncHttpResponseHandler
	 * @return
	 */
	public AsyncHttpResponseHandler getAsyncHttpResponseHandler(
			HttpMethod method, final String url,
			final CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		StringBuffer aCacheKeyBuffer = new StringBuffer();
		aCacheKeyBuffer.append(method.toString()).append(url);
		Logger.i(TAG, "aCacheKeyStr:" + aCacheKeyBuffer.toString());

		final String aCacheKey = String.valueOf(aCacheKeyBuffer.toString()
				.hashCode());
		Logger.i(TAG, "aCacheKey:" + aCacheKey);

		AsyncHttpResponseHandler asyncHttpResponseHandler = new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody) {
				if (statusCode == 200) {
					String resultString = new String(responseBody);
					Log.i(TAG, "resultString：" + resultString);

					JSONObject jsonObjectAll = null;
					try {
						jsonObjectAll = new JSONObject(resultString);
						if (jsonObjectAll.getInt("errcode") == 0) {
							if (cacheAsyncHttpResponseHandler != null) {
								if (aCache != null) {
									aCache.put(aCacheKey, responseBody,
											cacheTime);
								}
								cacheAsyncHttpResponseHandler.onSuccess(
										statusCode, headers, responseBody);
							}
						} else {
							cacheAsyncHttpResponseHandler.onSuccess(statusCode,
									headers, responseBody);
							if (isInterceptError && toastTools != null) {
								int code = jsonObjectAll.getInt("errcode");
								String errmsg = "";
								errmsg = jsonObjectAll.getString("errmsg");
								toastTools.showToast(context, code, errmsg);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			}

			@Override
			public void onFailure(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody,
					Throwable error) {
				error.printStackTrace();
				Logger.i(TAG, "statusCode:" + statusCode);
				if (isInterceptError && toastTools != null) {
					toastTools.showToast(context, statusCode, "");
				}
				if (cacheAsyncHttpResponseHandler != null) {
					if (aCache != null && null != aCache.getAsBinary(aCacheKey)) {
						byte[] aCacheResponseBody = aCache
								.getAsBinary(aCacheKey);
						cacheAsyncHttpResponseHandler.onSuccess(200, null,
								aCacheResponseBody);
					} else {
						cacheAsyncHttpResponseHandler.onFailure(statusCode,
								headers, responseBody, error);
					}
				}
			}

		};
		return asyncHttpResponseHandler;
	}

	/**
	 * 获得请求响应信息
	 * 
	 * @param url
	 * @param requestParams
	 * @param cacheAsyncHttpResponseHandler
	 * @return
	 */
	public AsyncHttpResponseHandler getAsyncHttpResponseHandler(
			HttpMethod method, final String url,
			final RequestParams requestParams,
			final CacheAsyncHttpResponseHandler cacheAsyncHttpResponseHandler) {
		if (netLoadProcess != null) {
			netLoadProcess.showLoading();
		}
		StringBuffer aCacheKeyBuffer = new StringBuffer();
		aCacheKeyBuffer.append(method.toString()).append(url)
				.append(requestParams.toString());
		Logger.i(TAG, "aCacheKeyStr:" + aCacheKeyBuffer.toString());

		final String aCacheKey = String.valueOf(aCacheKeyBuffer.toString()
				.hashCode());
		Logger.i(TAG, "aCacheKey:" + aCacheKey);

		AsyncHttpResponseHandler asyncHttpResponseHandler = new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody) {
				if (statusCode == 200) {
					String resultString = new String(responseBody);
					Log.i(TAG, "resultString：" + resultString);

					JSONObject jsonObjectAll = null;
					try {
						jsonObjectAll = new JSONObject(resultString);
						if (jsonObjectAll.getInt("errcode") == 0) {
							if (cacheAsyncHttpResponseHandler != null) {
								if (aCache != null) {
									aCache.put(aCacheKey, responseBody,
											cacheTime);
								}
								cacheAsyncHttpResponseHandler.onSuccess(
										statusCode, headers, responseBody);
							}
						} else {
							cacheAsyncHttpResponseHandler.onSuccess(statusCode,
									headers, responseBody);
							if (isInterceptError && toastTools != null) {
								int code = jsonObjectAll.getInt("errcode");
								String errmsg = "";
								errmsg = jsonObjectAll.getString("errmsg");
								toastTools.showToast(context, code, errmsg);
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
						toastTools.showToast(context, 666, "");
					}

					if (netLoadProcess != null) {
						netLoadProcess.showData();
					}
				}

			}

			@Override
			public void onFailure(int statusCode,
					org.apache.http.Header[] headers, byte[] responseBody,
					Throwable error) {
				error.printStackTrace();
				Logger.i(TAG, "statusCode:" + statusCode);

				switch (statusCode) {
				case 0:
					if (netLoadProcess != null) {
						netLoadProcess.showNoNet();
					}
					break;
				case 400:
					break;
				case 502:
					break;
				case 403:
					if (!InitUitls.getInitSessionUrl().equals(""))
						InitUitls.initSession(context);
					break;

				default:
					break;
				}
				if (isInterceptError && toastTools != null) {
					toastTools.showToast(context, statusCode, "");
				}

				if (cacheAsyncHttpResponseHandler != null) {
					if (aCache != null && null != aCache.getAsBinary(aCacheKey)) {
						byte[] aCacheResponseBody = aCache
								.getAsBinary(aCacheKey);
						cacheAsyncHttpResponseHandler.onSuccess(200, null,
								aCacheResponseBody);
					} else {
						cacheAsyncHttpResponseHandler.onFailure(statusCode,
								headers, responseBody, error);
					}
				}
			}

		};
		return asyncHttpResponseHandler;
	}

	@Override
	public void setNetLoadProcess(NetLoadProcess netLoadProcess) {
		this.netLoadProcess = netLoadProcess;
	}

}
